using TMPro;
using Unity.Collections;
using Unity.Entities;
using Unity.Physics;
using Unity.Transforms;
using Unity.VisualScripting;
using UnityEngine;

public class EnemyCount : MonoBehaviour
{
    EntityManager entityManager;
    EntityQuery entityQuery;
    NativeArray<EnemyCounter> enemyCounterEntities;
    TMP_Text enemyCountText;
    private void Start()
    {
        entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        enemyCountText = GetComponent<TMP_Text>();
    }
    
    void FixedUpdate()
    {
        entityQuery 
            = new EntityQueryBuilder(Allocator.Temp).WithAll<EnemyCounter>().Build(entityManager);
        enemyCounterEntities = entityQuery.ToComponentDataArray<EnemyCounter>(Allocator.Temp);
        enemyCountText.text = "Enemy Count: " + enemyCounterEntities[0].enemyCount;
        entityQuery.Dispose();enemyCounterEntities.Dispose();
    }
}
